<template>
  <div :class="(unUploadSubWinOpen && !businessIdAuto) ? 'folder-main' : ''">
    <div v-if="(unUploadSubWinOpen && !businessIdAuto)" class="view-tab">
      <div :class="tabActive === 'default' ? 'view-active' : ''" @click="changeView('default')">{{ $t('默认视图') }}</div>
      <div v-hasPermi="['deal:dealbase:view']" :class="tabActive === 'busView' ? 'view-active' : ''" @click="changeView('busView')">{{ $t('项目视图') }}</div>
    </div>
    <!-- 业务视图 例如项目视图 -->
    <div v-if="tabActive !== 'default'" class="busViewMain">
      <folderBusView @getFolderBusViewId="getFolderBusViewId" />
    </div>
    <!-- 文档库 -->
    <div class="components-container magicHome" :style="{ width: ((unUploadSubWinOpen && !businessIdAuto) ? (tabActive === 'default' ? '100%' : '85%') : 'auto'), 'left': ((unUploadSubWinOpen && !businessIdAuto) ? 'auto' : '') }">
      <split-pane split="vertical" :min-percent="15" :default-percent="15" style="position:unset;">
        <template slot="paneL">
          <div class="leftArea">
            <div v-if="data !== null && data !== undefined" class="inputFilter">
              <el-input
                v-model="filterText"
                class="filterText"
                :maxlength="30"
                clearable
                size="small"
                :placeholder="$t('关键字')"
              >
                <template #append>
                  <el-button
                    v-if="addOneFolderSwitch"
                    class="el-icon-plus"
                    @click="createFolderMethod({ id: 'main', parentId: '0', isBuiltIn: '0', isNewFolder: false })"
                  />
                </template>
              </el-input>
            </div>
            <div style="height: calc(100% - 75px);overflow-y: auto;margin-right: -13px;">
              <!-- 我创建的 -->
              <div>
                <el-tree
                  ref="tree"
                  v-loading="folderLoading"
                  :data="data"
                  :props="defaultProps"
                  lazy
                  highlight-current
                  :expand-on-click-node="true"
                  :filter-node-method="filterNode"
                  style="font-size: 14px;"
                  :indent="10"
                  node-key="id"
                  :default-expanded-keys="expansionLevel"
                  :load="loadNode"
                  @node-expand="nodeExpand"
                  @node-collapse="nodeCollapse"
                >
                  <span slot-scope="{ node, data }" class="custom-tree-node" @click="getFileList(node, data)">
                    <div class="rows" style="-webkit-user-select:none">
                      <span class="titTree">
                        <el-tooltip :disabled="(data.businessId === undefined || data.businessId === null || data.businessId === '')" :content="$t('当前项目独有文件夹')">
                          <i :class="(data.businessId === undefined || data.businessId === null || data.businessId === '') ? 'el-icon-fold' : 'el-icon-fold-blue'" />
                        </el-tooltip>
                        <p :style="{ color: '#606266' }">{{ $t(node.label) }}</p>
                        <span style="display: none">{{ data }}</span>
                      </span>
                      <span v-show="unUploadSubWinOpen" class="more" style="display: block;">
                        <el-dropdown :disabled="data.fileLibraryRole.createDirectory !== 'Y'">
                          <span class="el-dropdown-link">
                            <i class="el-icon-more" style="transform: rotate(90deg);" />
                          </span>
                          <el-dropdown-menu slot="dropdown" class="dropdown-more">
                            <el-dropdown-item v-if="data.fileLibraryRole.createDirectory === 'Y'">
                              <span @click="createFolderMethod(data)">{{ $t('新建目录') }}</span>
                            </el-dropdown-item>
                            <el-dropdown-item v-if="(data.fileLibraryRole.createDirectory === 'Y') && data.id !== 'personal_files' && (!businessIdAuto || data.businessId)">
                              <span @click="editFolderMethod(data)">{{ $t('编辑目录') }}</span>
                            </el-dropdown-item>
                            <el-dropdown-item v-if="((data.isBuiltIn !== '1' && data.fileLibraryRole.createDirectory === 'Y') || (loginUser.admin && !directoryCannotBeDeletedByAdmin.includes(data.id))) && (!businessIdAuto || data.businessId)">
                              <span @click="delFolderMethod(data)">{{ $t('删除目录') }}</span>
                            </el-dropdown-item>
                          </el-dropdown-menu>
                        </el-dropdown>
                      </span>
                    </div>
                  </span>
                </el-tree>
              </div>
            </div>
            <div v-show="!businessIdAuto" class="more-dir">
              <ul v-show="unUploadSubWinOpen">
                <li class="dir-name" style="border-right: 1px solid #ececec;" @click="viewShareFile">
                  <div>
                    <el-tooltip class="item" effect="dark" :content="$t('分享')" placement="top">
                      <i class="el-icon-share" :title="$t('分享')" />
                    </el-tooltip>
                  </div>
                </li>
                <li class="dir-name" style="border-right: 1px solid #ececec;" @click="openCollection">
                  <div>
                    <el-tooltip class="item" effect="dark" :content="$t('收藏')" placement="top">
                      <i class="el-icon-star-off" :title="$t('收藏')" />
                    </el-tooltip>
                  </div>
                </li>
                <li style="border-right: 1px solid #ececec;" @click="openTheRecycleBin">
                  <div class="dir-name on">
                    <el-tooltip class="item" effect="dark" :content="$t('回收站')" placement="top">
                      <i class="el-icon-delete" :title="$t('回收站')" />
                    </el-tooltip>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </template>
        <!-- 内容区域 -->
        <template slot="paneR">
          <div class="rightContent" style="overflow:auto;height:100%;width:100%;">
            <div class="list-table" style="background: white;width: 98%;margin:15px auto;">
              <el-form ref="queryForm" :model="pageParams" :inline="true">
                <!-- showSearchName: 判断是不是个人或企业  otherBusinessId: 如果有值说明当前文档库在项目或基金里 -->
                <el-form-item v-if="showSearchName && otherBusinessId === ''" :label="formatName(thisPageFolder) + $t('名称')" prop="businessId">
                  <!-- 组件判断 -->
                  <spv-select v-if="subjectType === 'spv'" v-model="pageParams.businessId" :scope-authority="true" />
                  <el-select v-else-if="subjectType === 'company_portal_file'" v-model="pageParams.businessId">
                    <el-option
                      v-for="dict in targetCompaniesList"
                      :key="dict.dictValue"
                      :label="$t(dict.dictLabel)"
                      :value="dict.dictValue"
                    />
                  </el-select>
                  <MainBodySelect v-else v-model="pageParams.businessId" :show-label="false" :parameters="subjectType" :scope-authority="true" />
                </el-form-item>
                <el-form-item :label="$t('文件名称')" prop="fileName">
                  <el-input
                    v-model="pageParams.name"
                    size="small"
                    :placeholder="$t('文件名称')"
                    clearable
                  />
                </el-form-item>
                <el-form-item :label="$t('文件标签')" prop="fileTag">
                  <el-input
                    v-model="pageParams.fileTag"
                    size="small"
                    :placeholder="$t('文件标签')"
                    clearable
                  />
                </el-form-item>
                <el-form-item :label="recycleBinCollection !== 'HSZ' ? $t('上传人') : $t('删除人')">
                  <el-input
                    v-model="pageParams.nickName"
                    size="small"
                    :placeholder="$t('上传人')"
                    clearable
                  />
                </el-form-item>
                <el-form-item v-show="false" :label="$t('显示隐藏附件')" prop="hideStatus">
                  <el-select v-model="pageParams.hideStatus" size="small">
                    <el-option :label="$t('隐藏')" value="N" />
                    <el-option :label="$t('显示')" value="" />
                  </el-select>
                </el-form-item>
                <el-form-item :label="recycleBinCollection === 'HSZ' ? $t('修改时间') : $t('上传时间')">
                  <DatePicker
                    v-model="dateRange"
                    type="daterange"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="findFileListByFolderIdMethod">{{ $t("搜索") }}</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(true)">{{ $t("重置") }}</el-button>
                </el-form-item>
                <el-row v-if="recycleBinCollection !== 'HSZ' && unUploadSubWinOpen" :gutter="10" class="mb8">
                  <el-col :span="1.5">
                    <el-button
                      v-if="thisPageFolder.isBuiltIn !== '1' || builtInCatalogId.includes(thisPageFolder.id)"
                      :disabled="thisPageFolder.fileLibraryRole.upload !== 'Y'"
                      icon="el-icon-upload"
                      size="mini"
                      type="primary"
                      @click="uploader(false, undefined)"
                    >{{ $t('上传') }}</el-button>
                    <el-button
                      v-if="thisPageFolder.isBuiltIn === '1' && !builtInCatalogId.includes(thisPageFolder.id)"
                      :disabled="thisPageFolder.fileLibraryRole.upload !== 'Y'"
                      icon="el-icon-upload"
                      size="mini"
                      type="primary"
                      @click="uploader(true, thisPageFolder.id)"
                    >{{ $t('上传') }}</el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <el-tooltip :content="$t('先点击要打包的文件夹, 再进行此操作')" placement="top">
                      <el-button
                        v-if="configDownloadEnabled && showSearchName && recycleBinCollection !== 'HSZ' && recycleBinCollection !== 'SC'"
                        :disabled="folderLoading"
                        :icon="'el-icon-download'"
                        size="mini"
                        @click="packageDownload"
                      >{{ $t('打包下载') }}</el-button>
                    </el-tooltip>
                  </el-col>
                  <el-col :span="1.5">
                    <el-button
                      v-if="configDownloadEnabled"
                      :icon="downloadLoading ? 'el-icon-loading' : 'el-icon-download'"
                      size="mini"
                      :type="batchAction === 'download' ? 'primary' : ''"
                      @click="bulkDownLoad"
                    >
                      <span v-if="batchAction === 'download' && isEmpty(userMultipleFileList)">{{ $t('取消下载') }}</span>
                      <span v-else-if="batchAction === 'download' && !isEmpty(userMultipleFileList)">{{ $t('确定下载') }}</span>
                      <span v-else>{{ $t('批量下载') }}</span>
                    </el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <el-button
                      :icon="downloadLoading ? 'el-icon-loading' : 'el-icon-download'"
                      size="mini"
                      :type="batchAction === 'delete' ? 'primary' : ''"
                      @click="bulkDelete"
                    >
                      <span v-if="batchAction === 'delete' && isEmpty(userMultipleFileList)">{{ $t('取消删除') }}</span>
                      <span v-else-if="batchAction === 'delete' && !isEmpty(userMultipleFileList)">{{ $t('确定删除') }}</span>
                      <span v-else>{{ $t('批量删除') }}</span>
                    </el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <el-button
                      icon="el-icon-rank"
                      size="mini"
                      :type="batchAction === 'move' ? 'primary' : ''"
                      @click="bulkMove"
                    >
                      <span v-if="batchAction === 'move' && isEmpty(userMultipleFileList)">{{ $t('取消移动') }}</span>
                      <span v-else-if="batchAction === 'move' && !isEmpty(userMultipleFileList)">{{ $t('确定移动') }}</span>
                      <span v-else>{{ $t('批量移动') }}</span>
                    </el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <el-button
                      :icon="downloadLoading ? 'el-icon-loading' : 'el-icon-share'"
                      :type="batchAction === 'share' ? 'primary' : ''"
                      size="mini"
                      @click="saveShareFile"
                    >
                      <span v-if="batchAction === 'share' && isEmpty(userMultipleFileList)">{{ $t('取消分享') }}</span>
                      <span v-else-if="batchAction === 'share' && !isEmpty(userMultipleFileList)">{{ $t('确定分享') }}</span>
                      <span v-else>{{ $t('分享') }}</span>
                    </el-button>
                  </el-col>
                  <el-col v-if="thisPageFolder.belong === 'data_room'" :span="1.5">
                    <el-button
                      :icon="downloadLoading ? 'el-icon-loading' : 'el-icon-s-operation'"
                      :type="batchAction === 'bulkDataRoom' ? 'primary' : ''"
                      size="mini"
                      @click="bulkDataRoom"
                    >
                      <span v-if="batchAction === 'bulkDataRoom' && isEmpty(userMultipleFileList)">{{ $t('取消设置') }}</span>
                      <span v-else-if="batchAction === 'bulkDataRoom' && !isEmpty(userMultipleFileList)">{{ $t('确定设置') }}</span>
                      <span v-else>{{ $t('设置权限') }}</span>
                    </el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <div style="margin-top: 5px;">
                      <el-tooltip placement="top">
                        <div slot="content">
                          {{ $t('批量删除,批量下载, 批量移动, 分享 按钮说明:') }} <br>
                          {{ $t('以批量删除按钮为例:') }} <br>
                          {{ $t('第一次点击: 可以对附件进行勾选') }}<br>
                          {{ $t('第二次点击:') }} <br>
                          &nbsp;&nbsp;{{ $t('如果您勾选了附件复选框, 将对附件进行删除操作') }}<br>
                          &nbsp;&nbsp;{{ $t('如果您没有做任何选择, 取消操作') }}
                        </div>
                        <i class="el-icon-question" />
                      </el-tooltip>
                    </div>
                  </el-col>
                </el-row>
                <el-row v-if="recycleBinCollection === 'HSZ'" :gutter="10" class="mb8">
                  <el-col v-show="batchRestoreButton" :span="1.5">
                    <el-button
                      size="mini"
                      :type="batchAction === 'share' ? 'primary' : ''"
                      @click="batchRestoreFile"
                    >{{ $t('批量还原') }}</el-button>
                  </el-col>
                  <el-col v-show="batchDeleteButton" :span="1.5">
                    <el-button
                      size="mini"
                      :type="batchAction === 'share' ? 'primary' : ''"
                      @click="batchDeleteFile"
                    >{{ $t('批量删除') }}</el-button>
                  </el-col>
                </el-row>
              </el-form>
              <!-- -->
              <div v-loading="fileLoading" :element-loading-text="percentageNum">
                <div v-loading="fileLoading" :element-loading-text="percentageNum" style="margin: auto;">
                  <el-table
                    ref="multipleTable"
                    :data="fileList"
                    class="fileList"
                    :row-key="getRowKeys"
                    border
                    @select-all="multiOperationAll"
                    @select="multiOperation"
                    @sort-change="sortColumnSearch"
                    @cell-mouse-enter.once="rowDrop"
                  >
                    <el-table-column v-if="!isEmpty(batchAction) || !unUploadSubWinOpen" type="selection" width="40" prop="disabled" :selectable="multiOperationChoice" />
                    <el-table-column :label="$t('文件')" prop="name" sortable show-overflow-tooltip :min-width="300">
                      <template slot-scope="scope">
                        <div class="collection" style="overflow: hidden;text-overflow: ellipsis;">
                          <span v-if="recycleBinCollection !== 'HSZ'" class="handle" style="cursor:pointer;">
                            <i v-show="scope.row.isCollection !== 'file'" class="star el-icon-star-off" @click="collectionMethod(scope.$index ,'off',scope.row)" />
                            <i v-show="scope.row.isCollection === 'file'" class="star el-icon-star-on" @click="collectionMethod(scope.$index, 'on',scope.row)" />
                          </span>
                          <i :class="scope.row.icon" />
                          <!--回收站显示-->
                          <span v-if="recycleBinCollection === 'HSZ'">
                            <span>{{ $t(scope.row.name) }}</span>
                          </span>
                          <!--一般显示-->
                          <span v-else>
                            <el-link v-if="scope.row.fileLibraryRole.preview === 'Y'" type="primary" :underline="false" @click="onlinePreviewOnlineEdit('view', scope.row)">
                              {{ $t(scope.row.name) }}
                            </el-link>
                            <el-link v-else :underline="false" disabled style="color: #606266;">
                              {{ $t(scope.row.name) }}
                            </el-link>
                          </span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      v-if="showSearchName && !businessIdAuto"
                      prop="businessName"
                      :label="formatName(thisPageFolder) + $t('名称')"
                      sortable
                      :min-width="250"
                    >
                      <template slot-scope="scope">
                        {{ recycleBinCollection }}
                        <el-tooltip :content="scope.row.businessName" placement="right-end">
                          <span>{{ scope.row.businessName }}</span>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                    <el-table-column
                      v-if="thisPageFolder.belong === 'data_room'"
                      prop="dataRoomLpName"
                      :label="$t('可见出资人')"
                      :min-width="120"
                    >
                      <template slot-scope="scope">
                        <el-tooltip :content="scope.row.dataRoomLpName || $t('全部出资人可见')" placement="right-end">
                          <span>{{ scope.row.dataRoomLpName || $t('全部出资人可见') }}</span>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                    <el-table-column
                      v-if="thisPageFolder.belong === 'data_room'"
                      prop="dataRoomNotName"
                      :label="$t('不可见出资人')"
                      :min-width="120"
                    >
                      <template slot-scope="scope">
                        <el-tooltip :content="scope.row.dataRoomNotName" placement="right-end">
                          <span>{{ scope.row.dataRoomNotName }}</span>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                    <el-table-column prop="directoryName" :label="$t('文档类型')" width="130" sortable>
                      <template slot-scope="scope">
                        <span :title="scope.row.localhostPath" style="cursor: pointer;">{{ scope.row.directoryName }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="numbering" :label="$t('文件编号')" width="150" sortable>
                      <template slot-scope="scope">
                        {{ scope.row.numbering }}
                      </template>
                    </el-table-column>
                    <!--
                  <el-table-column prop="numbering" :label="$t('排序')" width="150" sortable>
                    <template slot-scope="scope">
                      {{ scope.row.rowSort }}
                    </template>
                  </el-table-column>
                  -->
                    <el-table-column prop="sizes" :label="$t('文件大小')" width="100" sortable>
                      <template slot-scope="scope">
                        <div class="collection">
                          <span>{{ calculateFileSize(scope.row.sizes) }} {{ calculateFileSize(scope.row.size) }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column v-if="recycleBinCollection !== 'HSZ'" prop="createBy.nickName" :label="$t('上传人')" width="100" sortable>
                      <template slot-scope="scope">
                        <div class="collection">
                          <span>{{ scope.row.createBy !== null ? scope.row.createBy.nickName : scope.row.updateBy.nickName }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column v-else prop="updateBy.nickName" :label="$t('删除人')" width="100" sortable>
                      <template slot-scope="scope">
                        <div class="collection">
                          <span>{{ scope.row.updateBy.nickName }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column v-if="recycleBinCollection !== 'HSZ'" prop="createTime" :label="$t('上传时间')" width="120" sortable>
                      <template slot-scope="scope">
                        <div class="collection">
                          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') || parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}') }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column v-else prop="updateTime" :label="$t('修改时间')" width="120" sortable>
                      <template slot-scope="scope">
                        <div class="collection">
                          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}') }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="fileTag" :label="$t('文件标签')" width="100" show-overflow-tooltip />
                    <el-table-column v-if="unUploadSubWinOpen" :label="$t('操作')" fixed="right" align="center" width="90">
                      <template slot-scope="scope">
                        <el-dropdown trigger="click">
                          <span class="el-dropdown-link"><i class="el-icon-more" /></span>
                          <!--文件的操作按钮-->
                          <div v-if="recycleBinCollection !== 'HSZ'">
                            <el-dropdown-menu slot="dropdown">
                              <a v-if="configDownloadEnabled" v-show="(scope.row.fileLibraryRole.downloadYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.downloadAll === 'Y'" @click="DownloadFile(scope.row.id)">
                                <el-dropdown-item>{{ $t('下载') }}</el-dropdown-item>
                              </a>
                              <el-dropdown-item v-show="scope.row.fileLibraryRole.move === 'Y'" @click.native="moveFile(scope.row)">
                                {{ $t('移动') }}
                              </el-dropdown-item>
                              <el-dropdown-item v-show="scope.row.fileLibraryRole.move === 'Y'" @click.native="copyFile(scope.row)">
                                {{ $t('复制') }}
                              </el-dropdown-item>
                              <el-dropdown-item v-if="typeContains(scope.row.suffix) && officeSwitchStatus && ((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y')" :disabled="scope.row.dataId !== null && scope.row.dataId !== ''" @click.native="onlinePreviewOnlineEdit('review', scope.row)">
                                {{ $t('编辑') }}
                              </el-dropdown-item>
                              <el-dropdown-item
                                v-show="((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y')"
                                @click.native="renameFile(scope.row, scope.$index)"
                              >{{ $t('命名') }}</el-dropdown-item>
                              <el-dropdown-item v-if="scope.row.fileLibraryRole.preview === 'Y'" @click.native="fileOrDirRecord(scope.row)">
                                {{ $t('日志') }}
                              </el-dropdown-item>
                              <el-dropdown-item v-if="scope.row.fileLibraryRole.preview === 'Y'" @click.native="discussionNotice(scope.row)">
                                {{ $t('讨论') }}
                              </el-dropdown-item>
                              <el-dropdown-item v-if="filePoteUserFlag && typeContainsAdjust(scope.row.suffix)" @click.native="errorCorrection(scope.row)">
                                {{ $t('检查') }}
                              </el-dropdown-item>
                              <el-dropdown-item @click.native="addFileTag(scope.row, scope.$index)">
                                {{ $t('标签') }}
                              </el-dropdown-item>
                              <!-- 当前有删除权限 或者 有上传权限, 并且上传人是自己时可以删除 -->
                              <el-dropdown-item
                                v-show="((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y') && (isEmpty(scope.row.dataId))"
                                @click.native="delFileBase(scope.row)"
                              >
                                {{ $t('删除') }}
                              </el-dropdown-item>
                              <el-dropdown-item
                                v-show="((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y') && (!isEmpty(scope.row.dataId)) && scope.row.hideStatus !== 'N'"
                                @click.native="batchHide(scope.row.id)"
                              >
                                {{ $t('删除') }}
                                <span style="display: none;">{{ scope.row.dataId }}</span>
                              </el-dropdown-item>
                              <!-- 回显 -->
                              <span>
                                <el-tooltip placement="left">
                                  <div slot="content">
                                    {{ $t('当前文件已从文档库隐藏, 点击该按钮可还原在文档库中的默认显示状态') }}
                                  </div>
                                  <el-dropdown-item
                                    v-if="scope.row.hideStatus === 'N' && ((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y')"
                                    @click.native="restoreEcho(scope.row)"
                                  >
                                    {{ $t('还原') }}
                                  </el-dropdown-item>
                                </el-tooltip>
                              </span>
                              <!-- 重新上传 -->
                              <el-dropdown-item v-show="scope.row.fileLibraryRole.upload === 'Y' && (scope.row.dataId === null || scope.row.dataId === '')">
                                <div>
                                  <el-tooltip class="item" effect="dark" :content="$t('上传一个新的的文件来替换该文件!')" placement="left">
                                    <reUpload
                                      ref="reUploadRef"
                                      :get-file-object="scope.row"
                                      :data-type="dataType"
                                      :icon-close="false"
                                      upload-style="border: none; font-size: 14px; font-weight: 350; margin: -8px;"
                                      @okPostUploadHook="okPostUploadHook"
                                      @replaceNewFile="replaceNewFile"
                                    />
                                  </el-tooltip>
                                </div>
                              </el-dropdown-item>
                              <el-dropdown-item v-show="thisPageFolder.belong === 'data_room'">
                                <span @click="fileDataRoomPermissions(scope.row)">{{ $t('权限') }}</span>
                              </el-dropdown-item>
                            </el-dropdown-menu>
                          </div>
                          <!--回收站文件的操作按钮-->
                          <div v-if="recycleBinCollection === 'HSZ'">
                            <el-dropdown-menu slot="dropdown">
                              <el-dropdown-item
                                v-show="((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y')"
                                :disabled="scope.row.updateBy.id !== loginUser.id && loginUser.id !== '1'"
                                @click.native="restoreFileBase(scope.row.id)"
                              >{{ $t('还原文件') }}</el-dropdown-item>
                              <el-dropdown-item
                                v-show="((scope.row.fileLibraryRole.deleteYourself === 'Y' && (scope.row.createBy !== null ? scope.row.createBy.id === loginUser.id : false)) || scope.row.fileLibraryRole.deleteAll === 'Y')"
                                :disabled="scope.row.updateBy.id !== loginUser.id && loginUser.id !== '1'"
                                @click.native="permanentlyDelete(scope.row.id)"
                              >{{ $t('彻底删除') }}</el-dropdown-item>
                            </el-dropdown-menu>
                          </div>
                        </el-dropdown>
                      </template>
                    </el-table-column>
                  </el-table>
                  <pagination
                    v-show="total > 0"
                    :total="total"
                    :page.sync="pageParams.pageNum"
                    :limit.sync="pageParams.pageSize"
                    @pagination="pageMethod"
                  />
                  <div style="height: 20px" />
                </div>
              </div>
            </div>
          </div>
          <div v-show="!unUploadSubWinOpen" class="selectBtn">
            <el-button size="mini" type="primary" @click="uploadChoiceToParent">{{ $t('选中') }}</el-button>
          </div>
        </template>
      </split-pane>

      <!-- 上传附件 -->
      <el-dialog v-if="uploaderOpen" v-el-drag-dialog :title="title" :visible.sync="uploaderOpen" :close-on-click-modal="false" width="50%" append-to-body>
        <Upload
          ref="uploadComponent"
          :data-type="dataType"
          :is-show-file-type="isShowFileType"
          :upload-business-type="uploadBusinessType"
          :single="false"
          :business-id="otherBusinessId"
          :main-body-select-choice="mainBodySelectChoice"
          @appendData="getData($event)"
        />
      </el-dialog>

      <!-- 新建文件夹 -->
      <el-dialog :title="title" :visible.sync="createFolderLoading" width="70%" :close-on-click-modal="false" custom-class="dialogForm" :destroy-on-close="true" append-to-body>
        <createFolder ref="createFolder" :folder-data="data" :business-id="otherBusinessId" @addToLeftFolderMenu="addToLeftFolderMenu" />
      </el-dialog>

      <!-- 添加或修改【移动或复制】对话框 -->
      <el-dialog :title="title" :visible.sync="formOpenMove" width="40%" height="50%" :close-on-click-modal="false" custom-class="dialogForm" :destroy-on-close="true" append-to-body>
        <copyTransferFiles ref="copyTransferFiles" />
      </el-dialog>

      <!--操作历史页面-->
      <el-dialog :title="title" :visible.sync="fileOrDirRecordLoading" top="5vh !important" width="80%" :close-on-click-modal="false" :destroy-on-close="true" :lock-scroll="false" custom-class="commentsDigOnly" append-to-body>
        <fileOperationRecord ref="fileOperationRecord" @versionRestoreClose="versionRestoreClose" />
      </el-dialog>

      <!-- 讨论通知 -->
      <el-dialog :title="$t('评论')" :visible.sync="commentsOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="commentsDigOnly" append-to-body>
        <comments ref="comments" />
      </el-dialog>

      <!-- 分享文件查看 -->
      <el-dialog :title="$t('文件分享')" :visible.sync="shareFilesListOpen" top="5vh !important" width="80%" :close-on-click-modal="false" :lock-scroll="false" custom-class="commentsDigOnly" append-to-body>
        <sysShareFilesList ref="sysShareFilesList" />
      </el-dialog>

      <!-- 分享form -->
      <el-dialog :title="$t('文件分享')" :visible.sync="shareFilesFormOpen" top="5vh" height="40%" width="60%" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
        <sysShareFilesForm ref="sysShareFilesForm" />
      </el-dialog>

      <el-dialog :title="$t('标签')" :visible.sync="tabsFormOpen" top="10%" height="30%" width="30%" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
        <fileTag ref="fileTag" @updateFileTag="updateFileTag" />
      </el-dialog>

      <el-dialog :title="$t('文档检查')" :visible.sync="examineOpen" width="300px" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
        <examine ref="examine" />
      </el-dialog>

      <el-dialog :title="$t('文件权限') + titleFilePermission" :visible.sync="openFilePermission" height="50%" width="30%" :close-on-click-modal="false" :destroy-on-close="true" append-to-body>
        <fileDataRoomPermission ref="fileDataRoomPermission" @saveFileDataRoom="saveFileDataRoom" />
      </el-dialog>

      <!-- 打包下载 -->
      <el-dialog :title="$t('打包下载') + ':' + thisPageFolder.name" :visible.sync="packageDownloadOpen" height="50%" width="30%" :close-on-click-modal="false" :destroy-on-close="true" append-to-body>
        <div>
          <el-form ref="packageForm" :inline="true">
            <el-form-item :label="formatName(thisPageFolder) + $t('名称')" prop="businessId">
              <spv-select v-if="subjectType === 'spv'" v-model="packageDownloadBusId" :scope-authority="true" />
              <el-select v-else-if="subjectType === 'company_portal_file'" v-model="packageDownloadBusId">
                <el-option
                  v-for="dict in targetCompaniesList"
                  :key="dict.dictValue"
                  :label="$t(dict.dictLabel)"
                  :value="dict.dictValue"
                />
              </el-select>
              <MainBodySelect v-else v-model="packageDownloadBusId" :show-label="false" :parameters="subjectType" :select-bus-type="packageDownloadBusType" :scope-authority="true" />
            </el-form-item>
            <div style="display: inline-flex;margin: 0 !important;">
              <el-button type="primary" @click="packageDownloadSubmit()">{{ $t('下载') }}</el-button>
            </div>
          </el-form>
        </div>
      </el-dialog>

      <!-- 附件预览 -->
      <OnlinePreview ref="OnlinePreview" :preview-type="dataType" />
    </div>
  </div>
</template>

<script>
import {
  findLeftList,
  findFileListByFolderId,
  openCollectionHome,
  theRecycleBin,
  insertCollection,
  cancelCollection,
  delFileFolder,
  deleteFileBase,
  recycleBinFile,
  updateFileId,
  batchDeletion,
  sortManually,
  batchHide, restoreEchoFile, fileClassTreeStructureSearch, renameFile
} from '@/api/file/filefolder/folder.js'
import { downLoadFileOpen, downLoadZip } from '@/utils/zipdownload'
import { getSysVarValue } from '@/api/system/config'
import { getLpView } from '@/api/base/deal/dealBase.js'
import { getLoginUser } from '@/api/system/user.js'
import { permanentlyDelete } from '@/api/file/fileBase.js'
import { getArrayByCode } from '@/api/file/directoryRelatedBusiness/directoryRelatedBusiness'
import { listDealTypeCompany } from '@/api/company/base/companyBase'
import MainBodySelect from '@/components/MainBodySelect'
import comments from '@/views/file/document/comments.vue'
import reUpload from '@/components/File/FileTable/subassembly/reUpload.vue'
import fileOperationRecord from '@/views/file/document/library/fileOperationRecord.vue'
import createFolder from '@/views/folder/createFolder.vue'
import copyTransferFiles from '@/views/file/document/library/copyTransferFiles.vue'
import sysShareFilesForm from '@/views/file/share/sysShareFilesForm.vue'
import sysShareFilesList from '@/views/file/share/sysShareFilesList.vue'
import SpvSelect from '@/components/Select/SpvSelect'
import fileTag from '@/views/file/fileTag/fileTag.vue'
import examine from '@/views/file/examine/examine.vue'
import Sortable from 'sortablejs'
import fileDataRoomPermission from '@/views/folder/fileDataRoomPermission/index.vue'
import folderBusView from '@/views/folder/folderBusView.vue'
import { config } from '@/utils'
import { getToken } from '@/utils/auth'
export default {
  components: {
    folderBusView,
    fileDataRoomPermission,
    SpvSelect,
    MainBodySelect,
    comments,
    fileOperationRecord,
    createFolder,
    copyTransferFiles,
    reUpload,
    examine,
    sysShareFilesList,
    sysShareFilesForm,
    fileTag
  },
  props: {
    // 非上传页面选择文档库
    unUploadSubWinOpen: {
      type: Boolean,
      default: () => true
    },
    // 指定文档类型
    folderBusType: {
      type: String,
      default: () => undefined
    },
    // 文档类型. 如果只显示某种项目类型. 只传入folderBusType, 如果想要精确显示某个项目下的文档则传入folderBusType和folderBusId
    folderBusId: {
      type: String,
      default: () => undefined
    }
  },
  data() {
    return {
      uploaderOpen: false,
      commentsOpen: false,
      examineOpen: false,
      filePoteUserFlag: false,
      shareFilesListOpen: false,
      shareFilesFormOpen: false,
      tabsFormOpen: false,
      fileOrDirRecordLoading: false,
      createFolderLoading: false,
      formOpenMove: false,
      mainBodySelectChoice: 'deal',
      dataType: 'fileLibrary',
      loading: false,
      title: '',
      rules: {},
      data: [],
      fileList: [],
      filterText: '',
      // 左侧文件夹 遮盖
      folderLoading: false,
      fileLoading: false,
      businessIdAuto: this.$route.query.id === undefined ? (this.$route.query.lpId === undefined ? undefined : this.$route.query.lpId) : this.$route.query.id,
      // 收藏或回收站
      recycleBinCollection: '',
      defaultProps: {
        label: 'name',
        children: 'children'
      },
      total: 0,
      // 日期范围
      dateRange: [],
      subjectType: '',
      pageParams: {
        id: '',
        businessId: undefined,
        name: undefined,
        keyword: undefined,
        nickName: undefined,
        createTime: undefined,
        isAsc: undefined,
        orderByColumn: undefined,
        fileTag: undefined,
        hideStatus: 'N',
        pageNum: 1,
        pageSize: 10,
        delFlag: '0'
      },
      // 最后一次点击的左侧文件夹对象
      thisPageFolder: {
        isBuiltIn: '1',
        fileLibraryRole: {
          preview: 'N',
          downloadYourself: 'N',
          downloadAll: 'N',
          upload: 'N',
          deleteYourself: 'N',
          deleteAll: 'N',
          createDirectory: 'N',
          move: 'N',
          shareYourself: 'N',
          shareAll: 'N'
        }
      },
      // 项目List页面会给这个参数传值, 用于创建目录
      dealBaseId: '',
      // 隐藏个人 公司的 搜索条件和列表业务名称
      showSearchName: false,
      // 批量选中的文件
      userMultipleFileList: [],
      // 批量操作前奏
      batchAction: undefined,
      officeSwitchStatus: '',
      // businessType otherBusinessId 当前是那种文档库 默认是 文档库, 其他的包括项目 deal 基金 fund 出资人 ...
      businessType: '',
      otherBusinessId: '',
      // 批量下载loading
      downloadLoading: false,
      // 进度条值
      percentageNum: '',
      // 内置目录的ID (新增的目录 需要添加一下)
      builtInDirectory: ['company_portal_file', 'data_room', 'debt_items', 'enterprise', 'equity_deal', 'equity_fund', 'fund', 'spv', 'investor_doc', 'personal_files', 'manager', 'fof', 'lease_deal'],
      // 管理员都不能删除的目录 (一般不动了)
      directoryCannotBeDeletedByAdmin: ['personal_files', 'enterprise', 'template', 'dealTemplate', 'fundTemplate'],
      // 一级目录新建开关, 项目基金里 不能新建目录
      addOneFolderSwitch: true,
      loginUser: {},
      // tree 默认展开那个目录
      expansionLevel: [],
      // 上传界面选中文件的Id
      toggleSelectionIds: [],
      // 是否来自菜单
      menuStatus: false,
      menuStatusId: '',
      // 批量还原
      batchRestoreButton: false,
      // 批量删除
      batchDeleteButton: false,
      // 非业务的内置目录
      builtInCatalogId: ['enterprise', 'personal_files', 'fundTemplate', 'dealTemplate'],
      // 所有需要关联目录的类型
      findListFormUploadTypeSelect: [],
      // 项目与文档关联关系
      vueUploadCurrDeptChange: [],
      // 下载按钮展示
      configDownloadEnabled: true,
      // 标的公司列表
      targetCompaniesList: [],
      isShowFileType: false,
      uploadBusinessType: undefined,
      // 单独文件权限 (dataRoom)
      openFilePermission: false,
      titleFilePermission: '',
      tabActive: 'default',
      packageDownloadOpen: false,
      packageDownloadBusId: '',
      packageDownloadBusType: '',
      // 项目视图选中的项目DI
      folderBusViewId: undefined,
      searchTimer: undefined
    }
  },
  watch: {
    filterText(val) {
      console.log('检索目录')
      if (val) {
        clearInterval(this.searchTimer)
        this.searchTimer = setInterval(() => {
          // 关闭懒加载
          this.$refs.tree.$data.store.lazy = false
          // 全部展开
          this.$refs.tree.$data.store.defaultExpandAll = true
          this.filterTextSearch(val)
          // 事件触发后,清除定时器
          clearInterval(this.searchTimer)
        }, 1000)
      } else {
        // 开启懒加载
        this.$refs.tree.$data.store.defaultExpandAll = false
        // 关闭全部展开
        this.$refs.tree.$data.store.lazy = true
        // 清除默认展开
        this.expansionLevel = []
        this.init()
      }
    },
    recycleBinCollection: {
      handler(val) {
        if (val === 'HSZ') {
          this.batchRestoreButton = true
          this.batchDeleteButton = true
        } else {
          this.batchRestoreButton = false
          this.batchDeleteButton = false
        }
      }
    },
    folderBusId: {
      handler(val) {
        if (val) {
          this.businessIdAuto = val
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    console.log('使用开关', this.$store.state.app.filePoteUser)
    if (this.$store.state.app.filePoteUser === 'Y') {
      this.filePoteUserFlag = true
    } else {
      this.filePoteUserFlag = false
    }
    console.log('使用开关赋值后的结果值', this.filePoteUserFlag)
  },
  mounted() {
    // 全局下载开关
    this.getConfigKeyToDownload('enable_download').then(response => {
      this.configDownloadEnabled = (response.msg === 'true')
    })
    // 关联关系 - 关联内置目录的ID
    getArrayByCode('vueFolder_builtInDirectory').then(response => {
      console.log('关联关系vb', response)
      if (response.data !== null) {
        response.data.forEach(item => {
          this.$nextTick(() => {
            this.builtInDirectory = item.busType
          })
        })
      }
    })
    getArrayByCode('javaArray_findListFormUploadTypeSelect').then(response => {
      console.log('关联关系jf', response)
      response.data.forEach(item => {
        this.findListFormUploadTypeSelect = item.busType
        /*
        *  股权项目  equity   equity_deal	股权项目
        *  债权项目  debt     debt_items	    债权项目
        *  参股基金  bf       equity_fund	参股基金
        */
        // 区分是那种文档库 (项目 基金. 出资人 , 文档库)
        if (this.unUploadSubWinOpen) {
          // 指定文档类型
          if (this.folderBusType !== undefined && this.folderBusType !== '') {
            this.businessType = this.folderBusType
            // 指定该文档类型下的改项目
            if (this.folderBusId !== undefined && this.folderBusId !== '') {
              this.otherBusinessId = this.folderBusId
            }
            this.init()
          } else {
            this.getLpType()
          }
        } else {
          // console.log('上传窗口,快速选择')
          this.addOneFolderSwitch = false
          this.businessType = ''
          this.otherBusinessId = ''
          this.init()
        }
      })
    })
    // 获取当前登录的用户
    getLoginUser().then(response => {
      if (response.code === 200) {
        this.loginUser = response.data
      }
    })
    // 获取文件上传展示的对应项目基金下拉框
    getArrayByCode('vueUpload_currDeptChange').then(response => {
      this.vueUploadCurrDeptChange = response.data
    })
    this.getOfficeSwitch()
  },
  beforeDestroy() {
  },
  methods: {
    // 区分是那种文档库 (项目 基金. 出资人 , 文档库)
    getLpType() {
      console.log('区分文档库')
      this.fileLoading = true
      this.folderLoading = true
      this.addOneFolderSwitch = true
      // 如果这里返回true, 则表示进入的是 自定义菜单文档库
      this.$emit('setMenuStatus', this)
      if (this.menuStatus === true) {
        this.$emit('getMenuFolderId', this, () => {
          this.businessType = this.menuStatusId
          this.addOneFolderSwitch = false
          this.init()
        })
      } else {
        // 针对出资人进行页面判断
        if (this.$route.path.indexOf('lpBase') !== -1) {
          if (this.getLpMenu() === 'DataRoom') {
            this.businessType = 'data_room'
            this.otherBusinessId = this.$route.query.id
            this.addOneFolderSwitch = false
          } else {
            this.businessType = 'investor_doc'
            this.otherBusinessId = this.$route.query.lpId
            this.addOneFolderSwitch = false
          }
          this.init()
        } else {
          // 针对项目基金 判断
          getLpView(this.$route.query.id).then(response => {
            if (response.data !== null && response.data.length > 0) {
              this.addOneFolderSwitch = false
              this.otherBusinessId = response.data[0].id
              if (this.$route.path.indexOf('fund/gpBase') !== -1) {
                this.businessType = 'manager'
              } else if (this.$route.path.indexOf('fund') !== -1) {
                // 区分基金和dataRoom
                if (this.getFundMenu() === 'DataRoom') {
                  this.businessType = 'data_room'
                } else {
                  if (this.$route.path.includes('spv') || this.$route.path.includes('Spv')) {
                    this.businessType = 'spv'
                  } else {
                    this.businessType = 'fund'
                  }
                }
              } else if (this.findListFormUploadTypeSelect.split(',').includes(response.data[0].dealType)) {
                // 项目类型的文档库 直接显示 // 判断一下 是不是股权 债权 参股基金 其中一种 如果不是 默认显示股权
                this.businessType = response.data[0].dealType
              } else {
                // 默认股权文档
                this.businessType = 'equity'
              }
            }
            // 母基金
            if (this.$route.query.fundType === 'fof') {
              this.businessType = 'fof'
              this.businessId = this.$route.query.id
            }
            // 根据结果进入不同的文档库
            this.init()
          })
        }
      }
    },
    // 获取LP出资人下的菜单名称
    getLpMenu(menu) {
      if (menu === undefined) {
        menu = this.$parent.$el.firstChild.firstChild.children
      }
      for (var i = 0; i < menu.length; i++) {
        if (menu[i].getAttribute('class').includes('active')) {
          return menu[i].outerText
        }
      }
    },
    // 获取基金下的菜单
    getFundMenu() {
      const menu = this.$parent.$el.firstChild.firstChild.children[0].children
      for (var i = 0; i < menu.length; i++) {
        if (menu[i].getAttribute('class').includes('active')) {
          return this.getLpMenu(menu[0].lastChild.children)
        }
      }
    },
    nodeExpand(data) {
      this.expansionLevel.push(data.id)
    },
    nodeCollapse(data) {
      this.expansionLevel.splice(this.expansionLevel.indexOf(data.id), 1)
    },
    init() {
      // 在项目里 第一次创建文件夹时 会刷页面. 这里做下 如果打开了 新建窗口不让刷新当前页面
      if (!this.createFolderLoading || this.$route.query.fundType === 'fof') {
        this.initMethod()
      }
    },
    initMethod() {
      this.filterText = undefined
      this.folderLoading = true
      this.fileLoading = true
      var businessIdQuery = this.businessIdAuto
      if (this.isEmpty(businessIdQuery)) {
        businessIdQuery = this.$route.query.id
      }
      console.log('加载文档库数据', businessIdQuery)
      findLeftList({ id: this.businessType, businessId: businessIdQuery, parentId: '0' }).then(response => {
        this.data = response.data
        if (this.data !== undefined && this.data !== null && this.data.length > 0) {
          if (!this.addOneFolderSwitch) {
            this.expansionLevel = [this.data[0].id]
          }
        }
        // 查询个人网盘的所有文件
        if (this.data !== null && this.data.length <= 0) {
          // this.msgError(this.$t('获取数据异常'))
          console.log('未能获取到该业务目录')
        }
        if (this.data !== null && this.data !== undefined && this.data.length > 0) {
          this.getFileList(null, this.data[0])
        } else {
          this.fileLoading = false
        }
        this.folderLoading = false
      })
    },
    loadNode(node, resolve) {
      var businessIdQuery = this.businessIdAuto
      if (this.isEmpty(businessIdQuery)) {
        businessIdQuery = this.$route.query.id
      }
      findLeftList({ id: this.businessType, businessId: businessIdQuery, parentId: node.data.id, belong: node.data.belong }).then(response => {
        resolve(response.data)
        this.folderLoading = false
      })
    },
    // 关键字搜索
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    filterTextSearch(searchQuery) {
      this.folderLoading = true
      fileClassTreeStructureSearch({ name: searchQuery, businessId: this.otherBusinessId }).then(response => {
        if (!this.isEmpty(response.data)) {
          this.data = response.data
        } else {
          this.data = []
        }
        this.folderLoading = false
      }).catch(() => {
        this.folderLoading = false
      })
    },
    // 点击左侧文件夹查询右侧文件
    getFileList(node, data) {
      // 清除页面排序
      this.$refs.multipleTable.clearSort()
      this.initializeProperties(data)
      this.findFileList(data)
    },
    // 每次点击文件夹重新初始化部分页面参数
    initializeProperties(data) {
      this.pageParams.delFlag = '0'
      // 初始化文档库和回收站状态
      this.recycleBinCollection = ''
      // 隐藏个人 公司的 搜索条件和列表业务名称
      if (this.builtInDirectory.includes(data.belong)) {
        this.showSearchName = true
        if (data.belong === 'personal_files' || data.belong === 'enterprise') {
          this.showSearchName = false
        }
      } else {
        this.showSearchName = false
      }
      // mainbody 类型 搜索框显示判断
      if (data.belong === 'debt_items') {
        this.subjectType = 'deal'
      } else if (data.belong === 'equity_deal') {
        this.subjectType = 'deal'
      } else if (data.belong === 'equity_fund') {
        this.subjectType = 'deal'
      } else if (data.belong === 'fund') {
        this.subjectType = 'fund'
      } else if (data.belong === 'data_room') {
        this.subjectType = 'fund'
      } else if (data.belong === 'investor_doc') {
        this.subjectType = 'lpInvestor'
      } else if (data.belong === 'manager') {
        this.subjectType = 'manager'
      } else if (data.belong === 'spv') {
        this.subjectType = 'spv'
      } else if (data.belong === 'company_portal_file') {
        this.subjectType = 'company_portal_file'
      }
      // 如果没有切换一级文件夹 查询条件不丢失
      if (this.thisPageFolder !== undefined) {
        if (this.thisPageFolder.belong !== data.belong) {
          this.resetQuery(false)
        }
      }
      if (data.id === 'company_portal_file') {
        // 如果点击了标的企业目录. 就加载标的企业的搜索下拉内容
        if (this.targetCompaniesList === undefined || this.targetCompaniesList == null || this.targetCompaniesList.length <= 0) {
          this.targetCompaniesList = []
          listDealTypeCompany({ companySource: 'DEAL_EQUITY' }).then(response => {
            if (response.rows !== null) {
              response.rows.forEach(item => {
                this.targetCompaniesList.push({ dictValue: item.id, dictLabel: item.companyName })
              })
            }
          })
        }
      }
      // 记录最后点击的 文件夹
      this.thisPageFolder = data
    },
    // 根据文件夹查询该文件夹及其子文件夹的文件
    findFileList(data) {
      this.pageParams.id = data.id
      this.findFileListByFolderIdMethod()
    },
    // findFileList 查询
    findFileListByFolderIdMethod() {
      this.fileLoading = true
      // 清空多选
      this.cancelBatch()
      this.pageParams.belong = this.thisPageFolder.belong
      // 在例如项目文档中会用到这个Id 只查这个项目的
      if (this.otherBusinessId !== '') {
        this.pageParams.businessId = this.otherBusinessId
      }
      if (this.recycleBinCollection === 'SC') {
        // 在收藏页面时搜索
        this.openCollection()
      } else if (this.recycleBinCollection === 'HSZ') {
        // 在回收站页面时搜索
        this.openTheRecycleBin()
      } else {
        findFileListByFolderId(this.addDateRange(this.pageParams, this.dateRange)).then(response => {
          this.fileList = response.rows
          this.total = response.total
          // 还原选中的文件
          this.toggleSelection()
          this.fileLoading = false
        })
      }
    },
    /**
     * 后台给显示内容排序
     * @param column
     */
    sortColumnSearch(column) {
      if (column.order !== null && column.prop !== 'dataRoomLpName' && column.prop !== 'dataRoomNotName') {
        if (column.order === 'descending') {
          this.pageParams.isAsc = 'desc'
          this.pageParams.orderByColumn = column.prop
        } else {
          this.pageParams.isAsc = 'asc'
          this.pageParams.orderByColumn = column.prop
        }
      } else {
        this.pageParams.isAsc = undefined
        this.pageParams.orderByColumn = undefined
        this.$refs.multipleTable.clearSort()
      }
      this.findFileListByFolderIdMethod()
    },
    // 搜索重置
    resetQuery(flag) {
      this.dateRange = []
      // 初始化查询条件
      this.pageParams = {
        id: '',
        businessId: undefined,
        name: undefined,
        keyword: undefined,
        nickName: undefined,
        createTime: undefined,
        hideStatus: 'N',
        pageNum: 1,
        pageSize: 10
      }
      // 清空多选
      this.cancelBatch()
      if (flag) {
        this.findFileList(this.thisPageFolder)
      }
    },
    // 分页类型
    pageMethod() {
      if (this.recycleBinCollection === 'SC') {
        this.openCollection()
      } else if (this.recycleBinCollection === 'HSZ') {
        this.openTheRecycleBin()
      } else {
        this.getFileList(null, this.thisPageFolder)
      }
    },
    // 预览附件
    onlinePreviewOnlineEdit(type, row) {
      this.$refs.OnlinePreview.onlinePreviewFile(row.id, type)
    },
    // 文件下载
    DownloadFile(id) {
      downLoadFileOpen(id)
    },
    // 删除附件
    delFileBase(row) {
      var that = this
      that.$confirm(that.$t('此操作将永久删除该文件, 是否继续?'), that.$t('提示'), {
        confirmButtonText: that.$t('确定'),
        cancelButtonText: that.$t('取消'),
        type: 'warning'
      }).then(() => {
        that.fileLoading = true
        deleteFileBase(row.id).then(response => {
          if (response.code === 200) {
            that.msgSuccess(that.$t('文件已删除!'))
            that.getFileList(null, that.thisPageFolder)
          } else {
            that.msgError(that.$t(response.msg))
          }
        })
      }).catch(() => {})
    },
    // 还原文件
    restoreFileBase(id) {
      this.fileLoading = true
      recycleBinFile(id).then(response => {
        if (response.code === 200) {
          this.msgSuccess(this.$t(response.msg))
          this.openTheRecycleBin()
        } else {
          this.msgError(this.$t(response.msg))
        }
        this.fileLoading = false
      })
    },
    /** 重命名文件 **/
    renameFile(row, index) {
      var _this = this
      this.$prompt('', this.$t('请录入新文件名称'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        beforeClose(action, instance, done) {
          if (action === 'confirm') {
            const fileName = instance.inputValue
            if (_this.isEmpty(fileName)) {
              _this.msgError(_this.$t('文件名称不能为空'))
            } else {
              // 正则表达式
              var regex = /^[\u4e00-\u9fa5a-zA-Z0-9]+(?:\.[\u4e00-\u9fa5a-zA-Z0-9]+)*$/
              // 检查文件名是否匹配正则表达式
              if (regex.test(fileName)) {
                done(fileName)
              } else {
                _this.msgError(_this.$t('文件名称包含非法字符'))
              }
            }
          } else {
            done()
          }
        }
      }).then((e) => {
        if (e.action === 'confirm') {
          var newName = e.value + row.name.substring(row.name.lastIndexOf('.'))
          renameFile({ id: row.id, name: newName }).then(response => {
            if (response.msg === 'success') {
              this.msgSuccess(this.$t('操作成功'))
            }
            this.$set(this.fileList[index], 'name', newName)
          })
        }
      })
    },
    // 移动附件
    moveFile(row) {
      this.formOpenMove = true
      this.title = this.$t('移动到')
      row.operationType = 'move'
      this.$nextTick(() => {
        this.$refs.copyTransferFiles.businessType = this.businessType
        row.belong = this.thisPageFolder.belong
        this.$refs.copyTransferFiles.init(row)
      })
    },
    // 复制文件
    copyFile(row) {
      this.formOpenMove = true
      this.title = this.$t('复制到')
      row.typeTemp = 'copy'
      this.$nextTick(() => {
        console.log('复制文件')
        this.$refs.copyTransferFiles.businessType = this.businessType
        this.$refs.copyTransferFiles.init(row)
      })
    },
    // 默认所有文件都可以勾选
    multiOperationChoice(row) {
      if (!this.unUploadSubWinOpen) {
        return true
      } else if (this.recycleBinCollection === 'HSZ') {
        if (this.batchAction === 'deleteRestore') {
          return ((row.fileLibraryRole.deleteYourself === 'Y' && (row.createBy !== null ? row.createBy.id === this.loginUser.id : false)) || row.fileLibraryRole.deleteAll === 'Y')
        } else if (this.batchAction === 'trueDeletion') {
          return ((row.fileLibraryRole.deleteYourself === 'Y' && (row.createBy !== null ? row.createBy.id === this.loginUser.id : false)) || row.fileLibraryRole.deleteAll === 'Y') && this.isEmpty(row.dataId)
        } else {
          return false
        }
      } else {
        if (this.batchAction === 'download') {
          return ((row.fileLibraryRole.downloadYourself === 'Y' && (row.createBy !== null ? row.createBy.id === this.loginUser.id : false)) || row.fileLibraryRole.downloadAll === 'Y')
        } else if (this.batchAction === 'delete') {
          return ((row.fileLibraryRole.deleteYourself === 'Y' && (row.createBy !== null ? row.createBy.id === this.loginUser.id : false)) || row.fileLibraryRole.deleteAll === 'Y')
        } else if (this.batchAction === 'move') {
          return (row.fileLibraryRole.move === 'Y') && this.isEmpty(row.dataId)
        } else if (this.batchAction === 'share') {
          return ((row.fileLibraryRole.shareYourself === 'Y' && (row.createBy !== null ? row.createBy.id === this.loginUser.id : false)) || row.fileLibraryRole.shareAll === 'Y')
        } else if (this.batchAction === 'bulkDataRoom') {
          return true
        } else {
          return false
        }
      }
    },
    // 多选操作
    multiOperation(selection, row) {
      if (row) {
        var selected = selection.length && selection.indexOf(row) !== -1
        // true就是选中，0或者false是取消选中
        // console.log('是否选中操作(单选): ' + selected)
      }
      const choiceCount = selection.length
      // 选中的大于0 展示批量下载
      if (choiceCount > 0) {
        // console.log('选中')
        if (selection) {
          selection.forEach(item => {
            if (!this.toggleSelectionIds.includes(item.id)) {
              this.userMultipleFileList.push(item)
              this.toggleSelectionIds.push(item.id)
            }
          })
          // console.log(this.userMultipleFileList, this.toggleSelectionIds, '---文档库选中的对象---')
        }
        // 取消选中
        if (row) {
          if (!selected) {
            if (this.toggleSelectionIds) {
              this.toggleSelectionIds.splice(this.toggleSelectionIds.findIndex(ids => ids === row.id), 1)
              this.userMultipleFileList.splice(this.userMultipleFileList.findIndex(list => list.id === row.id), 1)
            }
          }
        }
      } else {
        if (row) {
          if (!selected) {
            if (this.toggleSelectionIds) {
              this.toggleSelectionIds.splice(this.toggleSelectionIds.findIndex(ids => ids === row.id), 1)
              this.userMultipleFileList.splice(this.userMultipleFileList.findIndex(list => list.id === row.id), 1)
            }
          }
        }
      }
      this.removeDuplicateObjects()
    },
    // 全选操作
    multiOperationAll(selection) {
      if (selection.length > 0) {
        // console.log('全选')
        selection.forEach(item => {
          if (!this.toggleSelectionIds.includes(item.id)) {
            this.userMultipleFileList.push(item)
            this.toggleSelectionIds.push(item.id)
          }
        })
      } else {
        // console.log('取消当前页面全选')
        var fileList = this.fileList
        if (fileList) {
          fileList.forEach(item => {
            if (this.toggleSelectionIds.includes(item.id)) {
              this.toggleSelectionIds.splice(this.toggleSelectionIds.findIndex(ids => ids === item.id), 1)
              this.userMultipleFileList.splice(this.userMultipleFileList.findIndex(list => list.id === item.id), 1)
            }
          })
        }
      }
      // console.log('---文档库选中的对象---', this.userMultipleFileList, '---文档库选中的对象的Id---', this.toggleSelectionIds)
      this.removeDuplicateObjects()
    },
    // 选中的对象(list类型) userMultipleFileList  选中的对象Id(Set) toggleSelectionIds, 保证对象的数量不大于Id
    removeDuplicateObjects() {
      if (this.userMultipleFileList && this.toggleSelectionIds) {
        const setToggleSelectionIds = Array.from(new Set(this.toggleSelectionIds))
        this.userMultipleFileList.forEach((item, index) => {
          if (!setToggleSelectionIds.includes(item.id)) {
            this.userMultipleFileList.splice(index, 1)
          }
        })
      }
    },
    // 回收站彻底删除文件
    permanentlyDelete(id) {
      var that = this
      that.$confirm(that.$t('此操作将永久删除该文件, 是否继续?'), that.$t('提示'), {
        confirmButtonText: that.$t('确定'),
        cancelButtonText: that.$t('取消'),
        type: 'warning'
      }).then(() => {
        permanentlyDelete(id).then(response => {
          if (response.code === 200) {
            that.msgSuccess(that.$t('文件已删除!'))
            that.openTheRecycleBin()
          } else {
            that.msgError(that.$t(response.msg))
          }
        })
      }).catch(() => {})
    },
    // 回收站  批量删除
    batchDeleteFile() {
      if (this.batchAction === 'trueDeletion') {
        if (!this.isEmpty(this.userMultipleFileList)) {
          var choiceId = []
          this.userMultipleFileList.forEach(item => {
            choiceId.push(item.id)
          })
          this.permanentlyDelete(choiceId.join(','))
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'trueDeletion'
        this.$refs.multipleTable.clearSelection()
        this.$forceUpdate()
      }
    },
    // 回收站 批量还原
    batchRestoreFile() {
      if (this.batchAction === 'deleteRestore') {
        if (!this.isEmpty(this.userMultipleFileList)) {
          var choiceId = []
          this.userMultipleFileList.forEach(item => {
            choiceId.push(item.id)
          })
          this.restoreFileBase(choiceId.join(','))
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'deleteRestore'
        this.$refs.multipleTable.clearSelection()
        this.$forceUpdate()
      }
    },
    // 批量下载
    bulkDownLoad() {
      if (this.batchAction === 'download') {
        var choiceFileList = this.userMultipleFileList
        if (choiceFileList !== null && choiceFileList !== undefined && choiceFileList.length > 0) {
          var choiceFileListId = []
          choiceFileList.forEach(item => {
            if ((item.fileLibraryRole.downloadYourself === 'Y' && (item.createBy !== null ? item.createBy.id === this.loginUser.id : false)) || item.fileLibraryRole.downloadAll === 'Y') {
              choiceFileListId.push(item.id)
            }
          })
          if (choiceFileListId.length === 0) {
            this.msgError(this.$t('您所选中的文件均无下载权限!'))
          } else {
            downLoadZip('/file/fileBase/common/downloadZip?fileId=' + choiceFileListId.join(','), this)
            console.log('批量下载开始')
            this.cancelBatch()
          }
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'download'
        this.$refs.multipleTable.clearSelection()
        this.$forceUpdate()
      }
    },
    /**
     * 取消批量操作
     */
    cancelBatch() {
      this.batchAction = undefined
      this.userMultipleFileList = []
      this.toggleSelectionIds = []
      this.$refs.multipleTable.clearSelection()
      this.$forceUpdate()
    },
    getFolderBusViewId(id) {
      this.folderBusViewId = id
    },
    /**
     * 打包下载
     */
    packageDownload() {
      this.packageDownloadBusId = this.businessIdAuto || this.folderBusViewId
      if (this.isEmpty(this.packageDownloadBusId)) {
        // 项目外
        this.packageDownloadOpen = true
        this.vueUploadCurrDeptChange && this.vueUploadCurrDeptChange.some(item => {
          if (item.busType === this.thisPageFolder.belong) {
            this.packageDownloadBusType = item.busAlias
          }
        })
      } else {
        // 项目内
        this.packageDownloadSubmit()
      }
    },
    /**
     * 下载打包附件提交
     */
    packageDownloadSubmit() {
      console.log(this.thisPageFolder)
      if (!this.isEmpty(this.packageDownloadBusId)) {
        window.open(config.baseURL + '/file/fileBase/packageDownload?id=' + this.thisPageFolder.belong + '&belong=' + this.thisPageFolder.belong + '&businessId=' + this.packageDownloadBusId + '&Authorization=' + getToken(), '_blank')
        this.packageDownloadOpen = false
      } else {
        this.msgError('无法下载!')
      }
    },
    downloadOpenLoading() {
      this.downloadLoading = true
      this.fileLoading = true
    },
    downloadCloseLoading() {
      this.percentageNum = ''
      this.downloadLoading = false
      this.fileLoading = false
      // 清空多选
      this.cancelBatch()
    },
    downloadProgress() {
      this.percentageNum = this.$t('正在下载...')
    },
    // 批量移动
    bulkMove() {
      if (this.batchAction === 'move') {
        var cantMoveList = []
        var tempBelong
        var businessId
        var choiceFileList = this.userMultipleFileList
        if (choiceFileList !== null && choiceFileList !== undefined && choiceFileList.length > 0) {
          var choiceFileListArr = []
          choiceFileList.forEach(item => {
            if (item.fileLibraryRole !== undefined && item.fileLibraryRole !== null) {
              if (item.fileLibraryRole.move === 'Y' && !(item.dataId !== undefined && item.dataId !== null && item.dataId !== '')) {
                choiceFileListArr.push(item)
                if (item.belong && !tempBelong) {
                  tempBelong = item.belong
                }
                if (item.businessId && !businessId) {
                  businessId = item.businessId
                }
              } else {
                cantMoveList.push(item)
              }
            }
          })
          // 不能操作文件提示
          if (cantMoveList.length > 0) {
            var msg = ''
            cantMoveList.forEach(item => {
              msg += '<span style="line-height: 2;">[' + item.name + ']</span>' + '<br>'
            })
            this.$notify.info({
              title: this.$t('移动提醒'),
              dangerouslyUseHTMLString: true,
              duration: 4500,
              message: msg + '<span>' + this.$t('以上文件来自表单或没有权限不允许移动!') + '</span>',
              position: 'bottom-right'
            })
          }
          if (choiceFileListArr.length > 0) {
            if (choiceFileListArr[0].belong === undefined || choiceFileListArr[0].belong === null) {
              choiceFileListArr[0].belong = this.thisPageFolder.belong
            }
          }
          // 移动文件批量
          if (choiceFileListArr.length > 0) {
            console.log(choiceFileListArr)
            this.formOpenMove = true
            this.title = this.$t('移动到')
            this.$nextTick(() => {
              this.$refs.copyTransferFiles.operatingSignal = 'bulkMove'
              this.$refs.copyTransferFiles.businessType = this.businessType
              this.$refs.copyTransferFiles.bulkInit(choiceFileListArr, businessId)
              this.cancelBatch()
            })
          }
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'move'
        this.$refs.multipleTable.clearSelection()
        this.$forceUpdate()
      }
    },
    // 批量删除
    bulkDelete() {
      if (this.batchAction === 'delete') {
        var that = this
        if (!this.isEmpty(that.userMultipleFileList)) {
          this.$confirm(this.$t('此操作将删除该文件, 是否继续?'), this.$t('提示'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
          }).then(() => {
            that.fileLoading = true
            var choiceFileList = that.userMultipleFileList
            if (!this.isEmpty(choiceFileList)) {
              var deleteByIds = []
              var hideByIds = []
              choiceFileList.forEach(item => {
                // dataId有值说明是隐藏
                if (this.isEmpty(item.dataId)) {
                  deleteByIds.push(item.id)
                } else {
                  hideByIds.push(item.id)
                }
              })
              if (this.isEmpty(deleteByIds)) {
                deleteByIds.push('-999')
              }
              if (this.isEmpty(hideByIds)) {
                hideByIds.push('-999')
              }
              console.log('批量删除数据', deleteByIds, hideByIds)
              Promise.all([this.batchDeletion2(deleteByIds), this.batchHide2(hideByIds)]).then(() => {
                that.getFileList(null, that.thisPageFolder)
                // 清空多选
                this.cancelBatch()
              })
            }
          }).catch(() => {
            that.fileLoading = false
          })
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'delete'
        this.$refs.multipleTable.clearSelection()
      }
    },
    /**
     * 隐藏文件
     */
    batchHide(id) {
      if (id) {
        var that = this
        that.$confirm(that.$t('此操作将删除该文件, 是否继续?'), that.$t('提示'), {
          confirmButtonText: that.$t('确定'),
          cancelButtonText: that.$t('取消'),
          type: 'warning'
        }).then(() => {
          that.fileLoading = true
          batchHide([id]).then(response => {
            if (response.code === 200) {
              that.msgSuccess(that.$t('操作成功!'))
              that.getFileList(null, that.thisPageFolder)
            } else {
              that.msgError(that.$t(response.msg))
            }
          })
        }).catch(() => {
        })
      } else {
        console.error('未发现文件ID')
      }
    },
    /**
     * 回显重新再文档库中显示
     */
    restoreEcho(row) {
      if (row && row.id) {
        const id = row.id
        this.fileLoading = true
        restoreEchoFile({ fileId: id }).then(response => {
          if (response.data && response.data > 0) {
            row.hideStatus = undefined
            this.msgSuccess(this.$t(response.msg))
            this.getFileList(null, this.thisPageFolder)
          }
        })
      }
    },
    /**
     * 删除附件操作
     */
    async batchDeletion2(deleteByIds) {
      return new Promise((resolve) => {
        batchDeletion(deleteByIds.join(',')).then(() => {
          resolve()
        })
      })
    },
    /**
     * 批量隐藏附件
     */
    async batchHide2(hideByIds) {
      return new Promise((resolve) => {
        batchHide(hideByIds.join(',')).then(() => {
          resolve()
        })
      })
    },
    /** 查看分享 */
    viewShareFile() {
      this.shareFilesListOpen = true
      this.$nextTick(() => {
        this.$refs.sysShareFilesList.getList()
      })
    },
    /** dataRoom 分配权限 **/
    bulkDataRoom() {
      if (this.batchAction === 'bulkDataRoom') {
        if (this.userMultipleFileList.length > 0) {
          this.openFilePermission = true
          this.titleFilePermission = ':' + this.$t('批量分配DataRoom权限')
          this.$nextTick(() => {
            if (this.isEmpty(this.userMultipleFileList)) {
              this.msgError(this.$t('未获取勾选的附件, 请刷新重试'))
            } else {
              this.$refs.fileDataRoomPermission.bulkInit(this.userMultipleFileList)
            }
          })
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'bulkDataRoom'
        this.$refs.multipleTable.clearSelection()
        this.$forceUpdate()
      }
    },
    /** 分享操作 **/
    saveShareFile() {
      if (this.batchAction === 'share') {
        if (this.userMultipleFileList.length > 0) {
          var shareArr = []
          this.userMultipleFileList.forEach(item => {
            if ((item.fileLibraryRole.shareYourself === 'Y' && (item.createBy !== null ? item.createBy.id === this.loginUser.id : false)) || item.fileLibraryRole.shareAll === 'Y') {
              shareArr.push(item)
            }
          })
          this.shareFilesFormOpen = true
          this.$nextTick(() => {
            this.$refs.sysShareFilesForm.init(shareArr)
            this.cancelBatch()
          })
        } else {
          this.cancelBatch()
        }
      } else {
        this.userMultipleFileList = []
        this.toggleSelectionIds = []
        this.batchAction = 'share'
        this.$refs.multipleTable.clearSelection()
        this.$forceUpdate()
      }
    },
    // 添加附件
    uploader(isShowClass, dirType) {
      this.fileId = this.thisPageFolder.id
      this.title = this.$t('上传附件')
      this.uploaderOpen = true
      this.isShowFileType = isShowClass
      this.uploadBusinessType = dirType
      this.$nextTick(() => {
        // 判断是否是dataRoom目录, 是的话需要展示出lp门户下拉. 让用户选择赋予权限. 也可以不选
        this.$refs.uploadComponent.parentFolder = this.thisPageFolder

        // 如果指定查看某个项目则,不允许再选择其他项目路或基金
        if (this.folderBusId !== null && this.folderBusId !== undefined && this.folderBusId !== '') {
          this.$refs.uploadComponent.mainBodyDisabled = true
        }
        var type
        /** 注释的这段代码尽量不要删除. 用于数据参考 */
        /*
        if (['equity_deal', 'equity_fund', 'debt_items', 'estate_deal'].includes(this.thisPageFolder.belong)) {
          type = 'deal'
        } else if (['fund', 'data_room'].includes(this.thisPageFolder.belong)) {
          type = 'fund'
        } else if (['investor_doc'].includes(this.thisPageFolder.belong)) {
          type = 'lpInvestor'
        } else if (['manager'].includes(this.thisPageFolder.belong)) {
          type = 'manager'
        } else if (['company_portal_file'].includes(this.thisPageFolder.belong)) {
          type = 'company_portal_file'
        } else if (['spv', 'SPV'].includes(this.thisPageFolder.belong)) {
          type = 'spv'
        }
        */
        /** 注释的这段代码尽量不要删除. 用于数据参考 */
        console.log('上传文件')
        this.vueUploadCurrDeptChange.some(item => {
          if (item.busType === this.thisPageFolder.belong) {
            type = item.busOther
            // 如果是项目判断差哪种类型的项目
            if (item.busAlias !== undefined && item.busAlias !== null && item.busAlias.trim() !== '') {
              this.$refs.uploadComponent.selectBusType = item.busAlias
            }
            return true
          }
        })
        this.$refs.uploadComponent.mainBodyChoice = type
        this.$refs.uploadComponent.init()
      })
    },
    // 刷新附件列表
    getData(data) {
      // 更改文件的file_id
      this.fileLoading = true
      data.fileList.forEach(item => {
        if (this.isEmpty(item.directoryId)) {
          item.directoryId = this.thisPageFolder.id
        }
        item.createTime = undefined
      })
      console.log(data.fileList)
      updateFileId(data.fileList).then(() => {
        this.getFileList(null, this.thisPageFolder)
      })
    },
    // 收藏操作
    collectionMethod(index, type, data) {
      if (type === 'off') {
        data.isCollection = 'file'
        // 收藏
        insertCollection(data.id, data.fileType).then(() => {
          this.fileLoading = false
        })
      } else {
        this.fileLoading = true
        data.isCollection = ''
        // 取消收藏
        cancelCollection(data.id).then(() => {
          if (this.recycleBinCollection === 'SC') {
            this.fileList.splice(index, 1)
          }
          this.fileLoading = false
        })
      }
    },
    // 单独使用: 把dataRoom名称改成基金文档
    formatName(data) {
      if (data.belong === 'data_room' || data.belong === 'fund') {
        return this.$t('基金')
      } else if (data.belong === 'manager') {
        return this.$t('管理人')
      } else if (data.belong === 'debt_items' || data.belong === 'equity_deal') {
        return this.$t('项目')
      } else if (data.belong === 'equity_fund') {
        return this.$t('参股基金')
      } else if (data.belong === 'spv') {
        return this.$t('spv')
      }
      return this.$t(data.belongName)
    },
    // 回收站
    openTheRecycleBin() {
      this.fileLoading = true
      this.recycleBinCollection = 'HSZ'
      this.pageParams.delFlag = '1'
      this.userMultipleFileList = []
      theRecycleBin(this.addDateRange(this.pageParams, this.dateRange)).then(response => {
        this.loading = true
        if (response.code !== 200) {
          this.msgError(this.$t(response.msg))
        }
        this.fileList = response.rows
        this.total = response.total
        this.fileLoading = false
      })
    },
    // 打开收藏
    openCollection() {
      this.fileLoading = true
      this.recycleBinCollection = 'SC'
      this.pageParams.delFlag = '0'
      this.userMultipleFileList = []
      openCollectionHome(this.addDateRange(this.pageParams, this.dateRange)).then(response => {
        this.fileList = response.rows
        this.total = response.total
        for (var i = 0; i < this.fileList.length; i++) {
          this.fileList[i].isCollection = 'file'
        }
        this.fileLoading = false
      })
    },
    // 创建文件夹
    createFolderMethod(data) {
      this.createFolderLoading = true
      this.title = this.$t('新建文件夹')
      this.$nextTick(() => {
        var tempData = JSON.parse(JSON.stringify(data))
        var oneFolderType
        tempData.isNewFolder = true
        this.vueUploadCurrDeptChange.some(item => {
          if (item.busType.includes(tempData.belong)) {
            oneFolderType = item.remark
          }
        })
        // dealBaseId 是专门为项目List页面打开后新建目录用的
        this.$refs.createFolder.dealBaseId = this.dealBaseId
        this.$refs.createFolder.init(tempData)
        this.$refs.createFolder.initTreeData(this.data, oneFolderType)
      })
    },
    // 一级目录
    addToLeftFolderMainMenu(data, topData, isNewFolder) {
      data.level = 0
      data.children = topData.children
      // 如果时修改 先删掉 原来的
      if (!isNewFolder) {
        this.data.forEach((item, index) => {
          if (parseInt(item.sort) === parseInt(topData.sort) && item.name === topData.name) {
            this.data.splice(index, 1)
          }
        })
      }
      // 赋值
      var parentData = { children: this.data }
      // 当前目录的sort
      var sort = parseInt(data.sort)
      if (sort === undefined || sort === null || isNaN(sort)) {
        parentData.children.unshift(data)
      } else {
        if (parentData.children !== null && parentData.children !== undefined && parentData.children.length > 0) {
          var sortIndex = this.getSubDataSortIndex(parentData, sort)
          parentData.children.splice(sortIndex, 0, data)
        } else {
          if (parentData.children === null || parentData.children === undefined) {
            parentData.children = []
          }
          parentData.children.unshift(data)
        }
      }
    },
    // 新建的文件夹 刷新到页面列表
    addToLeftFolderMenu(data, topData, isNewFolder, oneFolder) {
      // 如果目录移动了走这里. 建议直接刷新页面. 否则递归会占内存 开发难度也较大
      if (data.parentId !== topData.parentId) {
        this.initMethod()
      } else if (oneFolder) {
        this.addToLeftFolderMainMenu(data, topData, isNewFolder)
      } else {
        if (isNewFolder) {
          // 新增
          if (topData.children === undefined || topData.children === null || topData.children === '') {
            topData.children = []
          }
          data.belong = topData.belong
          data.belongName = topData.belongName
          // topData.children.unshift(data)
          this.addArrayElementsToTheSpecifiedSubscript(topData, data)
        } else {
          // 编辑
          this.data.some((one, index) => {
            if (one.id === data.id) {
              this.data.splice(index, 1)
            } else {
              // 二级及以下的文件夹
              this.updateLeftMenuFolderChildren(one, data, topData)
            }
          })
        }
        this.$forceUpdate()
      }
      this.initMethod()
    },
    // 刷新编辑的文件夹
    updateLeftMenuFolderChildren(folder, data, topData) {
      // 二级文件夹递归查找删除
      if (folder.children !== undefined && folder.children !== '' && folder.children !== null) {
        folder.children.forEach((two, index) => {
          if (two.id === data.id) {
            folder.children.splice(index, 1)
            data.children = topData.children
            this.addArrayElementsToTheSpecifiedSubscript(folder, data)
          } else {
            this.updateLeftMenuFolderChildren(two, data, topData)
          }
        })
      }
    },
    // 按顺序放到目录指定位置
    addArrayElementsToTheSpecifiedSubscript(parentData, subData) {
      // 当前目录的sort
      var sort = parseInt(subData.sort)
      if (sort === undefined || sort === null || sort === '' || isNaN(sort)) {
        parentData.children.unshift(subData)
      } else {
        if (parentData !== undefined && parentData.children !== null && parentData.children !== undefined && parentData.children.length > 0) {
          var sortIndex = this.getSubDataSortIndex(parentData, sort)
          parentData.children.splice(sortIndex, 0, subData)
          this.$forceUpdate()
        } else {
          if (parentData.children === null || parentData.children === undefined) {
            parentData.children = []
          }
          parentData.children.unshift(subData)
        }
      }
    },
    // 编辑文件夹
    editFolderMethod(row) {
      this.createFolderLoading = true
      this.title = this.$t('编辑文件夹')
      console.log('编辑目录')
      this.$nextTick(() => {
        var oneFolderType
        var tempData = JSON.parse(JSON.stringify(row))
        tempData.isNewFolder = false
        this.$refs.createFolder.init(tempData)
        this.vueUploadCurrDeptChange.some(item => {
          if (item.busType.includes(tempData.belong)) {
            oneFolderType = item.busType
          }
        })
        this.$refs.createFolder.initTreeData(this.data, oneFolderType)
      })
    },
    /**
     * 根据子目录的下标确定
     * 情况1: 存在子目录: 仅有1个子目录
     * 情况2: 存在子目录: 多个子目录
     * 情况3: 不存在子目录 :无子目录
     */
    getSubDataSortIndex(parentData, sort) {
      if (parentData !== undefined && parentData.children !== undefined && parentData.children !== null && parentData.children.length > 0) {
        // 情况1 + 情况2
        var sortArr = []
        // 因为目录是排序好的  直接取序号
        parentData.children.forEach((item) => {
          var parTemp = this.formatNum(item.sort)
          sortArr.push(parTemp)
        })
        // 首位添加最大序号和最小序号
        sortArr.unshift(0)
        sortArr.push(999)
        // 获取sort 在哪两个序号之间
        return this.getClosestValues(sortArr, sort)
      } else {
        // 情况3
        return [0, 1000]
      }
    },
    // 获取下标
    getClosestValues(array, value) {
      var low = 0
      var high = 0
      array.forEach((item, i) => {
        if (low <= value && low < item) {
          low = item
          high = i
        }
      })
      // 获取sort 在哪两个序号之间, 最终返回插入的下标
      // console.log([array[high - 1], array[high], high])
      return high - 1
    },
    // 数字校验
    formatNum(num) {
      num = parseInt(num)
      if (isNaN(num)) {
        num = 0
      }
      return num
    },
    // 删除文件夹
    delFolderMethod(data) {
      var that = this
      this.$confirm(this.$t('将会删除当前及其子文件夹及其文件,是否确认?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
      .then(function() {
        that.folderLoading = true
        delFileFolder(data.id, data.id, data.belong).then(response => {
          if (response.code === 200) {
            that.msgSuccess(that.$t(response.msg))
            // 获取该目录的父级目录, 不刷新形式删除
            // that.deleteFileFolderRefresh(that.thisPageFolder.parentId, that.thisPageFolder.id)
            that.init()
          } else {
            that.msgError(that.$t(response.msg))
          }
          that.folderLoading = false
        })
      }).catch(function() {
        // console.log('取消删除文件夹?发生异常!')
        that.folderLoading = false
      })
    },
    /** 删除目录方法专用, 根据子目录ID制定刷新父级数据进行刷新页面 **/
    // deleteFileFolderRefresh(parentId, id) {
    //   this.$refs.tree.$data.root.childNodes && this.$refs.tree.$data.root.childNodes.forEach(item => {
    //     if (item.data.id === parentId) {
    //       this.thisPageFolder = item.data
    //       item.childNodes.forEach((item2, index) => {
    //         if (item2.data.id === id) {
    //           item.childNodes.splice(index, 1)
    //         }
    //       })
    //       this.getFileList(null, this.thisPageFolder)
    //     } else {
    //       this.deleteFileFolderRefreshSub(item, parentId, id)
    //     }
    //   })
    // },
    // deleteFileFolderRefreshSub(data, parentId, id) {
    //   data.childNodes && data.childNodes.forEach(item => {
    //     if (item.data.id === parentId) {
    //       this.thisPageFolder = item.data
    //       item.childNodes.forEach((item2, index) => {
    //         if (item2.data.id === id) {
    //           item.childNodes.splice(index, 1)
    //         }
    //       })
    //       this.getFileList(null, this.thisPageFolder)
    //     } else {
    //       this.deleteFileFolderRefreshSub(item, parentId, id)
    //     }
    //   })
    // },
    // 查看操作历史
    fileOrDirRecord(row) {
      this.fileOrDirRecordLoading = true
      this.title = this.$t('操作历史')
      this.$nextTick(() => {
        this.$refs.fileOperationRecord.fileDirId = row.id
        this.$refs.fileOperationRecord.init()
      })
    },
    // 讨论通知
    discussionNotice(row) {
      this.commentsOpen = true
      this.$nextTick(() => {
        this.$refs.comments.init(row.discussId)
        this.$refs.comments.discussFileId = row.id
      })
    },
    // 文档纠错（文档审核）
    errorCorrection(row) {
      this.examineOpen = true
      this.$nextTick(() => {
        this.$refs.examine.init(row)
      })
    },
    // 添加标签
    addFileTag(row, index) {
      console.log(row)
      this.tabsFormOpen = true
      this.$nextTick(() => {
        this.$refs.fileTag.init(row, index)
      })
    },
    /**
     * 修改dataRoom权限后更新页面数据
     * @param data
     * @param isBulk
     */
    saveFileDataRoom(data, isBulk) {
      console.log(data)
      if (!isBulk) {
        this.fileList.forEach(item => {
          if (item.id === data.fileId) {
            item.dataRoomLpName = data.lpNames
            item.dataRoomNotName = data.lpNotNames
          }
        })
      } else {
        this.getFileList(null, this.thisPageFolder)
      }
    },
    // 刷新标签内容
    updateFileTag(data, index) {
      this.fileList[index].fileTag = data.fileTag
    },
    // 新创建的讨论. 因为页面上的 文件还没有id 这里创建完后 把讨论Id赋值给这个文件
    discussionNoticeRefresh(discussId, fileId) {
      // console.log(discussId, fileId)
      if (discussId && fileId) {
        this.fileList.forEach(item => {
          if (item.id === fileId) {
            item.discussId = discussId
          }
        })
      }
    },
    // 重新上传loading
    okPostUploadHook() {
      this.fileLoading = true
    },
    // 刷新重新上传的文件
    replaceNewFile(data) {
      if (data === null || data === undefined) {
        this.msgError(this.$t('没有发现被替换的文件!'))
      } else {
        this.getFileList(null, this.thisPageFolder)
      }
    },
    // 打开dataRoom文件权限
    fileDataRoomPermissions(row) {
      this.openFilePermission = true
      this.titleFilePermission = ': ' + row.name
      this.$nextTick(() => {
        this.$refs.fileDataRoomPermission.init(row)
      })
    },
    // 文件版本还原操作完成后刷新页面
    versionRestoreClose() {
      this.fileOrDirRecordLoading = false
      this.findFileListByFolderIdMethod()
    },
    // 计算文件大小  换算单位
    calculateFileSize(size) {
      size = parseInt(size)
      if (size > 0 && size < 1048576) {
        return (size / 1024).toFixed(2) + ' KB'
      } else if (size > 1048576) {
        return (size / 1024 / 1024).toFixed(2) + ' MB'
      } else {
        return ''
      }
    },
    // 是否是office文件,涉及到文件编辑
    typeContains(suffixType) {
      const availableSuffixes = '.doc.docx.xls.xlsx.ppt.pptx'
      if (availableSuffixes.includes(suffixType)) {
        return true
      }
      return false
    },
    // 文档审核目前支持doc、docx、pdf格式文件审核，最大支持50w字，1GB大小的文件
    typeContainsAdjust(suffixType) {
      const availableSuffixes = '.doc.docx.pdf'
      if (availableSuffixes.includes(suffixType)) {
        return true
      }
      return false
    },
    /**            文档库选择文件start              **/
    // 将选中的文件发送到上传页面小窗口
    uploadChoiceToParent() {
      // console.log(this.userMultipleFileList)
      this.$emit('uploadChoiceToParent', this.userMultipleFileList, this.loginUser)
    },
    // 打开时选中已选择的文件
    toggleSelection() {
      const rowsId = this.toggleSelectionIds
      // console.log('folder中选中的Id.' + rowsId)
      if (rowsId) {
        // 点击确定后 关闭页面输入页面 继续后面操作
        if (this.total > 0) {
          this.$nextTick(() => {
            this.fileList.forEach((item, index) => {
              if (rowsId.includes(item.id)) {
                this.$refs.multipleTable.toggleRowSelection(this.fileList[index])
              }
            })
          })
        }
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    getRowKeys(row) {
      return row.id === null || row.id === undefined ? new Date().getTime() : row.id
    },
    rowDrop() {
      // 行拖拽
      const _this = this
      const tbody2 = this.$refs.multipleTable.$el.querySelector('.el-table__body-wrapper tbody')
      Sortable.create(tbody2, {
        handle: '.handle',
        animation: 500,
        fallbackOnBody: true,
        onChoose() {
          // 选择元素
          _this.fileList[_this.fileList.length - 1].fixed = false
          console.log('选择元素')
        },
        onUnchoose: function(evt) {
          // 取消选择元素
          if (evt) {
            _this.fileList[_this.fileList.length - 1].fixed = 'right'
            console.log('取消元素')
          }
        },
        onEnd(evt) {
          console.log(evt)
          _this.fileList.splice(evt.newIndex, 0, _this.fileList.splice(evt.oldIndex, 1)[0])
          var newArray = _this.fileList.slice(0)
          _this.fileList = []
          _this.$nextTick(() => {
            _this.fileList = newArray
            var numbering = ''
            var result = {}
            _this.fileList.forEach((item, index) => {
              console.log(item, index)
              // 如果移动到了最后一行
              if (index === evt.newIndex) {
                if (evt.newIndex === 0) {
                  numbering = (_this.fileList[index + 1].rowSort === null || _this.fileList[index + 1].rowSort === undefined) ? undefined : _this.fileList[index + 1].rowSort
                  if (numbering === undefined) {
                    numbering = _this.fileList[index + 1].numbering
                    numbering = numbering.substring(numbering.indexOf('-') + 1, numbering.length)
                  }
                  numbering = parseInt(numbering)
                  numbering += 1
                  item.rowSort = numbering
                  result = item
                  console.log(numbering, result)
                } else {
                  numbering = (_this.fileList[index - 1].rowSort === null || _this.fileList[index - 1].rowSort === undefined) ? undefined : _this.fileList[index - 1].rowSort
                  if (numbering === undefined) {
                    numbering = _this.fileList[index - 1].numbering
                    numbering = numbering.substring(numbering.indexOf('-') + 1, numbering.length)
                  }
                  numbering = parseInt(numbering)
                  // numbering -= 1
                  item.rowSort = numbering
                  result = item
                  console.log(numbering, result)
                }
              }
            })
            if (result) {
              _this.fileLoading = true
              sortManually(result).then(response => {
                if (response.data === 1) {
                  _this.msgSuccess(_this.$t('操作完成!'))
                } else {
                  _this.msgError(_this.$t('操作失败!'))
                }
                _this.fileLoading = false
              })
            }
          })
        }
      })
      this.$forceUpdate()
    },
    changeView(type) {
      this.folderBusViewId = undefined
      if (!this.folderLoading && !this.fileLoading) {
        this.tabActive = type
        if (type === 'default') {
          this.$route.query.id = undefined
          this.$route.query.dealType = undefined
          this.businessType = undefined
          this.pageParams.businessId = undefined
          this.otherBusinessId = undefined
          this.getLpType()
        }
      }
    },
    /**            文档库选择文件 end               **/
    // 判断用的是 畅写office  还是LibreOffice
    getOfficeSwitch() {
      getSysVarValue('office.changxie.enabled').then(response => {
        this.officeSwitchStatus = (response.data.office_changxie_enabled === 'true')
      })
    }
  }

}
</script>

<style type="text/scss" lang="scss" scoped>
.handle, .canDrag {
  cursor: pointer;
  user-select:none;
}

::v-deep .hover-row > td {
  background-color: #fff !important;
}

::v-deep .sortable-chosen > td {
  // 拖动的样式
  background-color: #eff2f6 !important;
}

::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
  // 修复拖拽的时候hover的不消失的问题
  background-color: #fff;
}
</style>

<style lang="scss" scoped>
.moveButtonDisabled {
  color: rgb(255, 255, 255);
  background-color: #9940aa94;
  border-color: rgba(215, 206, 217, 0.58);
}
.moveButtonActive {
  color: rgb(255, 255, 255);
  background-color: #9940BB;
  border-color: #9940BB;
}
.components-container {
  position: absolute;
  margin: 0;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.iframe {
  margin:0;
  padding:0;
  position:absolute;
  width:100%;
  top: 0;
  bottom:0;
}

.collection a {
  font-size: 14px;
}

.el-breadcrumb {
  line-height: 40px;
}

.el-tree {
  font-size: 14px;
  color: #606266;
  height: calc(100% - 70px);
  overflow: auto;
  margin-right: -20px;
  padding-right: 10px;
  margin-left: -10px;
}

.custom-tree-node {
  overflow: hidden;
  word-break: keep-all;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.custom-tree-node .tit{
  display: flex;
  align-items: flex-end;
  width: 100%;
}
.custom-tree-node p{
  margin: 0;
  flex: 1;
  overflow: hidden;
  word-break: keep-all;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.documentFile {
  background: #fff;
  width: auto;
  padding: 20px;
  height: 100%;
}

.documentFile .el-input {
  margin-bottom: 10px;
}

.more-dir {
  position: absolute;
  bottom: 0px;
  left: 0;
  right: 0;
  border-top: 1px solid #ececec;
}
.inputFilter{
  display: flex;
  align-items: baseline;
  column-gap: 10px;
}

.more-dir ul {
  background: #fff;
  display: flex;
}

.more-dir li {
  height: 44px;
  line-height: 44px;
  cursor: pointer;
  font-size: 15px;
  color: #606266;
  flex: 1;
  text-align: center;
}
.more-dir li i{
  font-weight: bold;
}
.more-dir li:first-child {
  border-right: 1px solid #ececec;
}

.documentContent {
  margin-left: 20px;
  margin-right: 20px;
  height: calc(100% - 75px);
}
.fileDoc {
  display: block;
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  -ms-flex-preferred-size: auto;
  flex-basis: auto;
  box-sizing: border-box;
  min-height: calc(100vh - 85px);
  position: relative;
  margin: -15px;
}
.el-icon-star-on{
  color: #ffa55c!important;
  font-size: 25px!important;
  margin-left: -2px!important;
}
.magicHome .splitter-paneL .leftArea .el-tree .custom-tree-node {
  width: 100%;
  height: 35px;
  padding: 8px 0;
}
.tabRadio {
  margin: 0 0 5px 5px;
}
.busViewMain {
  width: 14.3%;
  height: 100%;
  overflow-y: auto;
  position: absolute;
  background: white;
  left: 0;
  top: 0;
}
/deep/.el-radio__input {
  // display: none;
}
/deep/.el-radio__label{
  // padding-left: 0;
}
button.el-button.el-icon-plus.el-button--default.el-button--medium {
  width: 20px;
  text-align: center;
  display: inline-block;
  margin: -10px -20px -20px -25px;
}
.folder-main {
  position: absolute;
  left: 40px;
  top: 0;
  right: 0;
  bottom: 0;
  padding-left: 40px;
}
.view-tab {
  position: absolute;
  left: -40px;
  width: 40px;
  height: 100%;
  background: white;
  border-right: 1px solid #eee;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  div {
    padding: 15px 10px;
    color: #5a5a5a;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    font-size: 15px;
  }
}
.view-active {
  color: #1890ff;
}
.disable-active {
  z-index: 1;
  position: absolute;
  left: -40px;
  width: 40px;
  height: 100%;
  background: white;
  border-right: 1px solid #eee;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  div {
    padding: 15px 10px;
    color: #5a5a5a;
    border-bottom: 1px solid #eee;
    cursor: wait;
    font-size: 15px;
  }
}
.dropdown-more{
  .el-dropdown-menu__item{
    padding: 0;
    span{
      display: block;
      padding: 0 17px;
    }
  }
}
</style>

